export default class battery {
  constructor() {
    this.enabled = false
    //this.interval = "game" //ui game normal
    this.data = { level: 0, isCharging : false }
  }
  startSuccess () { }
  startFail() { }
  startComplete () { }

  change(data) {
    this.data.changed = 
      this.data.level  == data.level && 
      this.data.isCharging == data.isCharging
    this.data.level = data.level
    this.data.isCharging = data.isCharging
    if (this.data.changed) {
      this.onChanged.bind(this)()
    }
  }
  start() {
    wx.getBatteryInfo({
      success: this.change.bind(this),
      fail: this.startFail.bind(this),
      complete: this.startComplete.bind(this)
    })
    this.id = requestAnimationFrame(this.start.bind(this))
    this.enabled = true
  }
  stop() {
    cancelAnimationFrame(this.id)
    this.enabled = false
  }
  onChanged() {}
}